<template>
  <div class="col main-content">
    <div class="row tool-bar">

      <div class="col">
        <div class="inline-item">
          <div class="label inline">
            买家:
          </div>
          <div class="inline">
            <h-user-choose v-model="search.applyId"></h-user-choose>
          </div>
        </div>

        <div class="inline-item">
          <div class="label inline">
            发货单号:
          </div>
          <div class="inline">
            <el-input v-model="search.sn" clearable></el-input>
          </div>
        </div>

        <div class="inline-item">
          <div class="label inline">
            订单日期:
          </div>
          <div class="inline">
            <h-date-range-picker v-model="search.date"/>
          </div>
        </div>
        <div class="inline-item">
          <el-button type="primary" @click="searchAction"><i class="fa fa-search"></i> 查询</el-button>
        </div>

        <div class="inline-item">
          <div class="label inline">
            排序:
          </div>
          <div class="inline">
            <el-radio-group v-model="orderName" @change="orderChange">
              <el-radio :label="2">按降序</el-radio>
              <el-radio :label="1">按升序</el-radio>
            </el-radio-group>
          </div>
        </div>

      </div>

    </div>
    <div class="row mt-15">
      <div class="col">
        <el-table
          :data="datas"
          border
          tooltip-effect="dark"
          v-loading="loading"

        >
          <el-table-column type="expand" label="详情">
            <template slot-scope="props">
              <el-table
                :data="props.row.details"
                tooltip-effect="dark"
                border
                stripe
              >
                <el-table-column
                  label="订单编号"
                  width="120" prop="sn">
                </el-table-column>
                <el-table-column
                  label="商品信息"
                  min-width="280">
                  <template slot-scope="scope">
                    <h-good-info-display :admin="true" v-model="scope.row"/>
                  </template>
                </el-table-column>
                <el-table-column
                  label="商品规格"
                  min-width="100"
                >
                  <template slot-scope="scope">
                    <h-specs-display v-model="scope.row"/>
                  </template>
                </el-table-column>

                <el-table-column label="订单信息" min-width="200">
                  <template slot-scope="scope">
                    <h-order-info-display v-model="scope.row"/>
                  </template>
                </el-table-column>
                <el-table-column
                  label="订单金额"
                  min-width="150">
                  <template slot-scope="scope">
                    <h-order-pay-info-display v-model="scope.row"/>
                  </template>
                </el-table-column>

                <el-table-column
                  label="状态信息" width="120" align="center">
                  <template slot-scope="scope">
                    <h-order-status-display v-model="scope.row" :apply="true" :dispatch="true" :arrival="true"
                                            :pay="true"/>
                  </template>
                </el-table-column>
              </el-table>
            </template>
          </el-table-column>
          <el-table-column
            prop="sn"
            label="发货单号"
            width="120">
          </el-table-column>
          <el-table-column label="快递信息" width="140">
            <template slot-scope="scope">
              <div>
                <div> {{scope.row.expressName}}</div>
                <el-button type="text" v-for="item in scope.row.expressPosts" :key="item"
                           @click="showExpressLog(scope.row.expressCode,item)">
                  {{item}}
                </el-button>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="nickName"
            label="买家信息"
            width="200">
            <template slot-scope="scope">
              <h-user-display v-model="scope.row.apply"></h-user-display>
            </template>
          </el-table-column>
          <el-table-column
            label="创建日期"
            width="160" prop="createTime">
          </el-table-column>
          <el-table-column
            label="联系信息"
            show-overflow-tooltip>
            <template slot-scope="scope">
              <div>联系人: {{scope.row.concat}}</div>
              <div>联系电话: {{scope.row.mobile}}</div>
              <div>联系地址: {{scope.row.district}} {{scope.row.address}}</div>
            </template>
          </el-table-column>
          <el-table-column
            label="件数"
            width="50">
            <template slot-scope="scope">
              <span class="red">{{scope.row.num}}</span>
            </template>
          </el-table-column>
          <el-table-column label="备注" prop="note">
          </el-table-column>

          <el-table-column
            label="操作" align="center" width="80" fixed="right">
            <template slot-scope="scope">
              <el-tooltip placement="top">
                <div slot="content">当发现快递信息有出入的时候进行更改操作</div>
                <el-button type="text" @click="doExpress(scope.$index,scope.row)">
                  更新快递
                </el-button>
              </el-tooltip>
            </template>
          </el-table-column>
        </el-table>
        <div class="h-pagination">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="search.pagination.page"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="search.pagination.size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="search.pagination.total">
          </el-pagination>
        </div>
      </div>
    </div>
    <h-express-dialog v-model="currentData" :show.sync="showExpressDialog" title="更新快递信息" btn-txt="更新快递信息"
                      @success="expressSuccess"></h-express-dialog>
    <h-post-log-dialog v-model="postInfo" :show.sync="showPostLogDialog" title="快递信息"></h-post-log-dialog>
  </div>
</template>
<style>

</style>
<script>
  import HDateRangePicker from 'src/components/common/HDateRangePicker'
  import HUserChoose from 'src/components/common/HUserChoose'
  import AdminService from 'src/service/admin'
  import HUserDisplay from 'src/components/common/display/HUserDisplay'
  import HOrderStatusDisplay from 'src/components/common/display/HOrderStatusDisplay'
  import HSpecsDisplay from 'src/components/common/display/HSpecsDisplay'
  import TableMix from 'src/components/table-mix'
  import HExpressDialog from 'src/components/admin/common/HExpressDialog'
  import HPostLogDialog from 'src/components/common/dialog/HPostLogDialog'
  import HGoodInfoDisplay from 'src/components/common/display/HGoodInfoDisplay'
  import HOrderInfoDisplay from 'src/components/common/display/HOrderInfoDisplay'
  import HOrderPayInfoDisplay from 'src/components/common/display/HOrderPayInfoDisplay'

  export default {
    name: 'AdminDispatched',
    components: {
      HExpressDialog,
      HDateRangePicker,
      HUserChoose,
      HUserDisplay,
      HOrderStatusDisplay,
      HSpecsDisplay,
      HPostLogDialog,
      HGoodInfoDisplay,
      HOrderInfoDisplay,
      HOrderPayInfoDisplay
    },
    mixins: [TableMix],
    data() {
      return {
        orderName: 2,
        datas: [],
        search: {
          dispatch: 1,
          sn: null,
          pagination: {
            total: 0,
            page: 1,
            limit: 10
          },
          applyId: null,
          date: [],
          needDetails: true,
          orderBy: 'id desc'
        },
        currentData: {},
        //发货单信息
        postInfo: null,
        loading: false,
        showPostLogDialog: false,
        showExpressDialog: false
      }
    },
    methods: {
      orderChange: function (v) {
        if (v == 1) {
          this.search.orderBy = "id"
        } else {
          this.search.orderBy = "id desc";
        }
        this.getDatas();
      },
      searchAction: function () {
        this.search.pagination.page = 1
        this.getDatas()
      },
      showExpressLog: function (code, post) {
        this.postInfo = {
          code: code,
          post: post
        }
        this.showPostLogDialog = true
      },
      expressSuccess: function (data) {
        this.getDatas()
        this.showExpressDialog = false
      },
      doExpress: function (index, data) {
        this.currentData = data
        this.showExpressDialog = true
      },
      getDatas: function () {
        const me = this
        me.loading = true
        AdminService.searchDelivery(me.search).then(ds => {
          if (ds != null) {
            me.datas = ds.datas
            me.search.pagination = ds.pagination
          }
          me.loading = false
        })
      },
      handleCurrentChange: function (page) {
        this.search.pagination.page = page;
        this.getDatas();
      },
      handleSizeChange: function (size) {
        this.search.pagination.limit = size;
        this.search.pagination.page = 1;
        this.getDatas();
      }
    },
    mounted: function () {
     // this.initTalbeHeight(260)
      this.getDatas()
    }
  }
</script>
